<template>
  <div id="login">
    <header>
      <h3>登录</h3>
    </header>
    <div id="content">
      <div>
        <h4>我要登录</h4>
        <div>
          <label for="username">姓名</label>
          <input
            id="username"
            type="text"
            v-model="username"
            placeholder="请输入姓名…"
          />
        </div>
        <div>
          <label for="password">密码</label>
          <input
            id="password"
            type="password"
            v-model="password"
            placeholder="请输入密码…"
          />
        </div>
        <div>
          <input @click="login" name="submit" type="submit" value="登录" />
        </div>

        <p id="1"></p>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "vant";

export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    login() {
      axios
        .post("/api/login/login.html", {
          username: this.username,
          password: this.password,
        })
        .then((res) => {
          var data = res.data;
          var json = eval("(" + data + ")");
          console.log(json.code);

          if (json.code == 200) {
            this.$store.commit("updateLogin", true);
            this.$router.push("./");
          } else {
            Toast.fail(json.msg);
          }
        });
    },
  },
};
</script>

<style lang="scss" scoped>
header {
  width: 100%;
  height: 50px;
  background-color: dodgerblue;
}
header h3 {
  color: white;
  text-align: center;
  padding-top: 10px;
}
#content div input {
  width: 90%;
  height: 30px;
  font-size: 16px;
  border-radius: 8px;
  margin-top: 10px;
}
#content input[type="submit"] {
  width: 100%;
  height: 30px;
  font-size: 16px;
  border-radius: 8px;
  margin-top: 10px;
  background-color: dodgerblue;
}
p {
  color: red;
}
</style>